package org.jiuling.network.tools.request.http.model;

import org.jiuling.local.tools.exception.LocalToolsException;
import org.jiuling.local.tools.util.EnumUtil;
import org.jiuling.network.tools.request.http.exception.HttpRequestRuntimeException;
import org.jiuling.network.tools.response.enums.HttpResponseStatus;

import java.io.InputStream;

/**
 * HTTP请求响应
 * @author 紫灵
 * @date 2022年04月16日 21时44分47秒
 */
public class HttpRequestResponse {

    /** 响应状态 */
    private HttpResponseStatus httpResponseStatus;
    /** 内容 */
    private String errorBody;
    /** 输入流 */
    private InputStream inputStream;
    /** 内容 */
    private String body;

    public HttpResponseStatus getHttpResponseStatus() {
        return httpResponseStatus;
    }

    public void setHttpResponseStatus(int responseStatus){
        try {
            this.httpResponseStatus = EnumUtil.valueOfEnum(HttpResponseStatus.class,responseStatus,"getStatus");
        } catch (LocalToolsException e) {
            throw new HttpRequestRuntimeException("未知响应类型："+responseStatus);
        }
    }

    public String getErrorBody() {
        return errorBody;
    }

    public void setErrorBody(String errorBody) {
        this.errorBody = errorBody;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
